package router

import (
	"enjoy-joy/client/client"
	"enjoy-joy/client/request"
	user "enjoy-joy/common/proto"
	"github.com/gin-gonic/gin"
)

func SendSms(c *gin.Context) {
	var data request.SendSms
	err := c.ShouldBind(&data)
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1000,
			"data": err.Error(),
		})
		return
	}

	sms, err := client.SendSms(c, &user.SendSmsReq{
		Mobile: data.Mobile,
		Source: data.Source,
	})
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1001,
			"data": err.Error(),
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 0,
		"data": sms,
	})

}
func UserLogin(c *gin.Context) {
	var data request.UserLoginOrRegister
	err := c.ShouldBind(&data)
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1000,
			"data": err.Error(),
		})
		return
	}
	register, err := client.UserLoginOrRegister(c, &user.UserLoginOrRegisterReq{
		Mobile: data.Mobile,
		Code:   data.Code,
	})
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1001,
			"data": err.Error(),
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 0,
		"data": register,
	})
}
func ClassList(c *gin.Context) {
	var data request.ClassList
	err := c.ShouldBind(&data)
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1000,
			"data": err.Error(),
		})
		return
	}
	list, err := client.ClassList(c, &user.ClassListReq{
		Page:     data.Page,
		Pagesize: data.Pagesize,
	})
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1001,
			"data": err.Error(),
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 0,
		"data": list,
	})
}
